package com.ccc.mq.consumer;

import com.ccc.test.common.pojo.OrderlyData;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 消息消费者(接收消息)——顺序消息
 *
 * @author superC
 * @version 1.0.0
 * @date 2022/9/15
 */

@Component
@RocketMQMessageListener(
        nameServer = "${base.config.rocketmq.nameServer}",
        topic = "${base.config.rocketmq.topic.orderlyTopic}",
        consumerGroup = "${base.config.rocketmq.consumer.group.orderlyGroup}",
        // 此处设置为ORDERLY，默认情况下是并发消费模式。
        consumeMode = ConsumeMode.ORDERLY
)
public class OrderlyConsumerService implements RocketMQListener<OrderlyData> {
    protected static final Logger logger = LoggerFactory.getLogger(OrderlyConsumerService.class);

    @Override
    public void onMessage(OrderlyData message) {
        logger.info("=======消息消费者-监听 receiveLog========");
        if (message == null) {
            logger.error("MQ消息为空或NULL值");
        }
        logger.info("===id: {}, ===name: {}, ===context: {}", message.getId(), message.getName(), message.getContent());

        // 业务处理

    }
}